package cn.iocoder.yudao.module.mybusiness.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mybusiness.domain.BussinessMod;
import cn.iocoder.yudao.module.mybusiness.domain.Facility;
import cn.iocoder.yudao.module.mybusiness.param.FacilityParam;
import cn.iocoder.yudao.module.mybusiness.service.FcfService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RequestMapping("/fcf")
@RestController
public class FcfController {

    @Autowired
    private FcfService fcfService;

    @GetMapping("/getList")
    @Operation(summary = "获取设备列表")
//    @PermitAll
    public CommonResult<PageResult<Facility>> getList(FacilityParam facilityParam){
        PageResult<Facility> pageResult = fcfService.getList(facilityParam);
        return success(pageResult);
    }

    @PutMapping("/create")
    @Operation(summary = "新增设备")
//    @PermitAll
    public CommonResult<Boolean> create(@RequestBody Facility facility){
        fcfService.create(facility);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "修改设备")
//    @PermitAll
    public CommonResult<Boolean> update(@RequestBody Facility facility){
        fcfService.updateById(facility);
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除设备")
    @PermitAll
    public CommonResult<Boolean> delete(@RequestParam("id") Long id){
        try {
            fcfService.delete(id);
            return success(true);
        } catch (Exception e) {
            return error(430,e.getMessage());
        }
    }


    @GetMapping("/getDeptFcfTree")
    @Operation(summary = "删除零件规格")
    @PermitAll
    public CommonResult<List> getDeptFcfTree(){
        List list = fcfService.getDeptFcfTree();
        return success(list);
    }
}
